from dataclasses import dataclass
from typing import Callable, ContextManager, Optional

import torch


class ForcedConfig:

    def __init__(self, underlying, **forced):
        assert not hasattr(underlying, 'underlying') and not hasattr(underlying, 'forced')
        object.__setattr__(self, 'underlying', underlying)
        object.__setattr__(self, 'forced', forced)

    def __getattr__(self, k):
        assert k not in ['underlying', 'forced']
        if k in self.forced:
            return self.forced[k]
        return getattr(self.underlying, k)

    def __setattr__(self, k, v):
        assert k not in ['underlying', 'forced']
        raise AttributeError('setattr disabled')
